package cn.auto.service;

import java.util.HashMap;
import java.util.List;

import cn.auto.common.model.Round;
import cn.auto.utility.Status;

public class RoundService {
	
	Round round= new Round();
	List<Round> infos=null;
	
	/**
	 * 获取所有round
	 * @return
	 */
	public HashMap<Object, Object> getRounds(String pid) {
		infos=round.searchRounds(pid);
		return Status.searchResultCode(infos);
	}
	
	/**
	 * 获取某一个round的信息
	 * @param id
	 * @return
	 */
	public HashMap<Object, Object> getRound(String id) {
		infos=round.searchRound(id);
		return Status.searchResultCode(infos);
	}
	
	public String addRound(HashMap<String, String> addInfo) {
		boolean isAdd=false;
		String pid = addInfo.get("pid");
		String name = addInfo.get("rname");
		String sid = addInfo.get("sid");
		String cli = addInfo.get("cli");
		String rerun = addInfo.get("rerun");
		isAdd = round.addRounds(name, sid, cli, pid,rerun);
		
		if(isAdd==true){
			infos=round.searchRounds(pid, name);
			Integer rid=infos.get(0).get("id");
			RuninfoService run= new RuninfoService();
			isAdd=run.addRunInfos(sid, pid, String.valueOf(rid));
		}
		return Status.booleanResultCode(isAdd);
	}
	
	public String delRound(String id) {
		boolean isDel=round.delRounds(id);
		return Status.booleanResultCode(isDel);
	}
	
}
